package com.cdxy.dmr.repository;

import com.cdxy.dmr.dataObject.SmsVerifyLogDO;
import com.cdxy.dmr.mapper.SmsVerifyLogMapper;
import com.cdxy.enums.KaptchaEnum;
import com.cdxy.model.dto.base.mybatis.BaseRepository;
import org.springframework.stereotype.Repository;

/**
 * <p>
 * 短信发送记录 服务实现类
 * </p>
 *
 * @author autoGenCode
 * @since 2020-03-05
 */
@Repository
public class SmsVerifyLogRepository extends BaseRepository<SmsVerifyLogMapper, SmsVerifyLogDO> {

    /**
     * 获取最近发送的验证码
     *
     * @param businessType
     * @param scene
     * @return
     */
    public SmsVerifyLogDO getByBusinessTypeAndSceneAndMobileOrderBySceneOrderByIdDesc(String businessType, KaptchaEnum.BusinessCode scene, String mobile) {
        return this.baseMapper.selectOne(this.queryWrapper()
                .eq(SmsVerifyLogDO::getBusinessType, businessType)
                .eq(SmsVerifyLogDO::getScene, scene.name())
                .eq(SmsVerifyLogDO::getMobile, mobile)
                .orderByDesc(SmsVerifyLogDO::getId)
                .last("LIMIT 1"));
    }

}
